package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.HopInventoryView;

public class HopInventoryViewPresenter extends AbstractPresenter<HopInventoryView> {
	final String SINGLEITEM = "hopInventoryView";
	final String MULTIITEM = "hopInventoryViews";
	
	public ArrayList<HopInventoryView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public HopInventoryView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public HopInventoryView createItemFromJSONObject(JSONObject jsonObject){
		HopInventoryView item = new HopInventoryView();
		try{
			item.setHid(jsonObject.getInt("hid"));
			item.setHopName(jsonObject.getString("hopName"));
			item.setHopOnHand(jsonObject.getDouble("hopOnHand"));
			item.setHopOnOrder(jsonObject.getDouble("hopOnOrder"));
			item.setHopSpoken(jsonObject.getDouble("hopSpoken"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(HopInventoryView item){
		try{
			JSONObject json = new JSONObject();
			json.put("hid", item.getHid());
			json.put("hopName", item.getHopName());
			json.put("hopOnHand", item.getHopOnHand());
			json.put("hopOnOrder", item.getHopOnOrder());
			json.put("hopSpoken", item.getHopSpoken());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public HopInventoryView getEmptyEntity(){
		HopInventoryView entity = new HopInventoryView();
		return entity;
	}
}
